﻿@page "/theme/create"
@attribute [Authorize(Roles = "User, Administrator")]
@inherits OwningComponentBase<ICovenantService>

@using Covenant.Core
@using Covenant.Models.Covenant
@inject NavigationManager NavigationManager

<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3">
    <h1 class="h2">Create Theme</h1>
</div>

<ThemeForm Theme="Theme" OnSubmit="OnCreate">
    <button type="submit" class="btn btn-primary">
        <span class="fe fe-plus"></span> Create
    </button>
</ThemeForm>

@code {
    [Parameter]
    public Theme Theme { get; set; } = new Theme();

    private async Task OnCreate(Theme theme)
    {
        try
        {
            this.Theme = await Service.CreateTheme(theme);
            NavigationManager.NavigateTo($"/covenantuser/index");
        }
        catch (Exception e) when (e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
        {
            // ModelState.AddModelError(string.Empty, e.Message);
            // return RedirectToAction(nameof(Create), new { id = launcher.Name });
        }
    }
}